<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let arr = [1, 2, 5, 6, 7, 5, 4, 3, 1, 2];

        //1.数组去重
        //通过扩展运算符进行数组转换
        let result = [...new Set(arr)];
        console.log('1.数组与集合互转:', result);

        //2.交集
        let arr2 = [6, 7, 8, 7, 8, 9];
        let result2 = [...new Set(arr)].filter(item => new Set(arr2).has(item));
        console.log('2.交集:', result2);

        //3.并集
        let union =[...new Set([...arr, ...arr2])];
        console.log('3.并集:', union);

        //4.差集
       let diff = [...new Set(arr)].filter(item => !(new Set(arr2).has(item)))
        console.log('4.差集:', diff);
    </script>
</body>

</html>